package com.sgb.kjwl.view.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.swgk.core.util.UiUtil;
import com.sgb.kjwl.view.ui.fragment.NewWebViewX5Fragment;
import com.ycbjie.webviewlib.view.X5WebView;

import androidx.fragment.app.FragmentManager;

/**
 * 作者:张磊
 * 日期:2021/1/26 0026
 * 说明:
 */
public class NewWebViewX5HostActivity extends AppActivity {
    public final static String TAG = "NewWebViewX5HostActivity";


    public static void start(Context context, String url, String data, String title,boolean isUser) {
        Intent intent = new Intent();
        intent.setClass(context, NewWebViewX5HostActivity.class);
        intent.putExtra("url", url);
        intent.putExtra("data", data);
        intent.putExtra("title", title);
        intent.putExtra("isUser", isUser);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_activity_web_view_x5_host);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        UiUtil.setStatusBarLightMode(this, true);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().add(R.id.ll_container, new NewWebViewX5Fragment()).commit();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        X5WebView mWebView = NewWebViewX5Fragment.getWebView();
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        } else {
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 上传图片之后的回调
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        Log.e("onActivityResult", "onActivityResult");
        NewWebViewX5Fragment.ActivityResult(requestCode, resultCode, intent);
    }

}